filter dataframe

35

filter pandas dataframe -

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)

Filter in pandas -

#Filtering for SP state and price up or equal 115
sp_above_mean = df[(df['price'] >= 115) & (df['seller_state'] == 'SP')]

pandas filter -

# select columns by name
>>> df.filter(items=['one', 'three'])
         one  three
mouse     1      3
rabbit    4      6

Comments

Submit
0 Comments